<?php
Yii::import('zii.widgets.jui.CJuiWidget');
class JQuiFormEnhancer extends CJuiWidget
{
	var $formId;
	var $textWidth;
	var $columnWidth;
	var $buttonWidth;
	
	var $filter=true;
	var $select=true;
	var $list=true;
	
	function run(){}
	
	public function init()
	{
		parent::init();
		$this->registerScripts();
	}
	
	protected function registerScripts() {
		parent::registerCoreScripts();
		$basePath=Yii::getPathOfAlias('application.extensions.JQuiFormEnhancer.vendors');
		$baseUrl = Yii::app()->getAssetManager()->publish($basePath);
		
		$cs=Yii::app()->getClientScript();
		$cs->registerCssFile($baseUrl . '/' . 'patch.css');
		
		$this->scriptUrl=$baseUrl;
		$this->registerScriptFile('ui.formenhancer.js');
		
		if($this->filter)
		{
			$cs->registerCssFile($baseUrl . '/' . 'jquery.multiselect.filter.css');
			$this->registerScriptFile('jquery.multiselect.filter.js');
		}
		
		if($this->select || $this->list)
			$cs->registerCssFile($baseUrl . '/' . 'jquery.multiselect.css');
		
		if($this->select)
			$this->registerScriptFile('jquery.multiselect.js');
                if($this->select)
                        $this->registerScriptFile('jquery.listselect.js');
		
		$params = array();
		if(isset($this->textWidth))
			$params[] = "textWidth:'".$this->textWidth."'";
		if(isset($this->columnWidth))
			$params[] = "columnWidth:'".$this->columnWidth."'";
		if(isset($this->buttonWidth))
			$params[] = "buttonWidth:'".$this->buttonWidth."'";
		$parameters = '{' .implode(',', $params). '}';
		Yii::app()->clientScript->registerScript('formEnhancer'.$this->formId, '$("#'.$this->formId.'").form('. $parameters .');', CClientScript::POS_READY);
		
	}
}